<%-------------------------------------------------------------------
 * 页面名称：drawToOther_1.jsp
 * 功能描述：账户直付－填写直付信息
 * Action  : drawToOther
 *
 *-------------------------------------------------------------------
--%>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="cn.agiledata.bank.common.util.WeatherUtil"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-bean.tld" prefix="bean"%>
<%@ taglib prefix="ad" uri="agiledata"%>
<%@ page import="cn.agiledata.bank.common.util.Constant"%>
<%
	String path = request.getContextPath();
	String basePath = Constant.WEBROOT_URL  + path;
	String accountId = String.valueOf(WeatherUtil
			.getAccountIdFromSession(request));
%>
<script type='text/javascript' src='<%=path%>/js/ufront.js'></script>
<script type='text/javascript'
	src='<%=path%>/dwr/interface/accountTemplate.js'></script>
<script language="javascript" type="text/javascript"
	src="<%=path%>/js/choiceCity.js"></script>
<script type='text/javascript'
	src='<%=path%>/dwr/interface/AccountLogic.js'></script>
<script type='text/javascript'
	src='<%=path%>/js/vnv/commonForCnAmount.js'></script>
<script type='text/javascript' src='<%=path%>/js/vnv/tomoney.js'></script>
<script type='text/javascript'
	src='<%=path%>/dwr/interface/peerAccountService.js'></script>
<SCRIPT LANGUAGE="JavaScript">
function update(){
    AccountLogic.getCityList(createList, $("creditProvinceId").value);
}
function createList(data){
	DWRUtil.removeAllOptions("creditCityId");
	DWRUtil.addOptions("creditCityId", data,'cityId','cityName');
}
function submitProcess() {
	if(!checkNecessaryInput(document.DrawToOtherForm)){
		return;
		
		}else
		{
		var creditAccountNo = document.all.creditAccountNo;
		var accountNo = creditAccountNo.value;
		if(isNaN(accountNo)==true){
			alert("请输入正确的收款方银行账号，账号中只能包含数字！");
			document.all.creditAccountNo.value="";
			creditAccountNo.focus();
			return; 	        			
		}
		if(accountNo.length<6||accountNo.length>32){
			alert("请输入正确的收款方银行账号，账号长度必须在6位到32位之间！");
			creditAccountNo.focus();
			return;
		}
		
		if(!checkEmail(document.DrawToOtherForm.creditEmail)){
			alert("请输入正确的收款方Email！");
			document.DrawToOtherForm.creditEmail.focus();
			return;
		}
		
		if (!mobileValidate(document.DrawToOtherForm.creditMobile)) {
			return;
		}
		
		if(isNaN(document.DrawToOtherForm.creditFixedTel.value)==true){
			alert("收款方电话必须是数字！");
			document.DrawToOtherForm.creditFixedTel.value="";
			document.DrawToOtherForm.creditFixedTel.focus();
			return;
		}
		
		if(document.DrawToOtherForm.remark.value.length>85){
			alert("备注长度不能大于85！");
			return;
		}
		var objSelect = document.getElementsByName("subAccountId")[0].value;
		accountTemplate.authentication(objSelect,showResult);
		
	}
}
function showResult(data)
{
	if(data=="true")
	{
		alert("您还未进行实名认证，不能使用该交易！");
		return;
	}else
	{
		var amount=document.getElementsByName("amount")[0].value;
		accountTemplate.confirmToRule("10",amount,show);
	}
}
function show(data){
		if(data=="true")
		{
			alert("对不起，您的交易金额不符合规则！");
			document.getElementsByName("amount")[0].focus();
			return;
		}
			document.DrawToOtherForm.submit();
	}

function updatePrompt(data) {
   if (data==2){
    	alert('此账户没有足够资金，请重新输入！');
    	document.DrawToOtherForm.amount.value="";
    	document.DrawToOtherForm.upperAmount.value="";
    	return;
   }
   if (data == 1){
     	alert('请输入直付金额！');
     	document.DrawToOtherForm.amount.focus();
    	document.DrawToOtherForm.upperAmount.value="";
    	return; 
    } 
}
function init(){
	UFront.initPage();
	DWREngine.setPreHook();
	DWREngine.setPostHook();
}
function kd()
{
	var ss=getObj("amount").value;
	ss = ss.replace(/ /g,"");
	if (ss=="") {
		getObj("upperAmount").value="";
		return;
	}
	
	var sDispMsg = getChineseCurrencyString(ss);
	if(sDispMsg==-1) sDispMsg="错误的金额!";
	if(sDispMsg==-2) sDispMsg="太长的金额!";
	getObj("upperAmount").value=sDispMsg;
}
function numToChinese(num){
	var chinese = Chinese(num);
	document.DrawToOtherForm.chinese.innerText= "大写："+chinese+"元";
}

function bankAccountSelect(){
 	agiledata.getUserInternal(peerBankAccountPopup);
}
function peerBankAccountPopup(data) {
  	if(data) {
	 	openLayer("<%=path%>/page/common/selectBankAccount.do");
	} else {
		location.href="<%=path%>/page/util/session_invalid.jsp";
	}      
}

	//add by zxj
	function prepareForAddPeerBankAccount(data) {
		if (data) {
			if (confirm("要将收款方信息添加到联系人吗？")) {
				addPeerBankAccount(document.DrawToOtherForm);
				document.DrawToOtherForm.submit();
			} else {
				document.DrawToOtherForm.submit();
			}
		} else {
			document.DrawToOtherForm.submit();
		}
	}

	//add by zxj
	if (window.ActiveXObject && !window.XMLHttpRequest) {
    	window.XMLHttpRequest = function() {
    		return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
    	};
    }//取得XMLHttpRequest对象
    
    //add by zxj
    function getRequestBody(oForm) {
		var aParams = new Array(); // 用来存储“名=值”对的数组
		for (var i = 0; i < oForm.elements.length; i++) {
			var sParam = encodeURIComponent(oForm.elements[i].name);
			// “名=值”对必须转换成URL编码格式，否则极有可能丢失数据，所
			//以调用了javascript内建的encodeURIComponent函数
			sParam += "=";
			sParam += encodeURIComponent(oForm.elements[i].value);
			aParams.push(sParam);
		}
		return aParams.join("&");
	}
	
    //add by zxj
    function addPeerBankAccount(formObj) {
    	var req=new XMLHttpRequest();
    	var sBody = getRequestBody(formObj);
    	if (req) {
    		req.onreadystatechange=function() {
    			if (req.readyState==4 && req.status==200) {//判断状态，4是已发送，200已完成
            		if (req.responseText=="0") {
						alert("添加联系人成功!");
					} else if (req.responseText=="1") {
						alert("添加联系人失败!");
					} else if (req.responseText=="2") {
						alert("该银行账户已存在联系人列表中!");
					}
                }
    		}
    		req.open('POST', '<%=basePath%>page/myspace/peerBankAccountAddBeforeDrawToOther.do', false);
    		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    		req.send(sBody);
    	}
    }
	function amountBlur(objAmount) {
		// 金额失去焦点方法
		if(checkDecimalInput(objAmount,0)&&getObj('subAccountId').value!='') {
			accountTemplate.compareAccountMoney(document.DrawToOtherForm.subAccountId.value,objAmount.value, updatePrompt);
		}
		tomoney('DrawToOtherForm','amount','hideTransAmt');
		kd();
	}

	function getSubAcctBal() {
		var subAcctId = document.getElementsByName("subAccountId")[0].value;
		accountTemplate.accountMoney(subAcctId, setBalance);
	}

	function setBalance(money) {
		getObj('subaccountBal').innerHTML = money + '元';
	}
</SCRIPT>
<div id="main">
	<div class="content_right">
		<div style="width: 745px; margin-left: 10px;">
			<div class="titleinfo">
				账户直付
			</div>
			<div class="edit_pass">
				<html:form action="drawToOther" method="post">
					<html:hidden property="step" />
					<html:hidden property="actionType" />
					<table width="100%" border="0" align="center" cellpadding="5"
						cellspacing="1">
						<tr>
							<td width="23%" align="right" height="35px;">
								付款子账户：
							</td>
							<td width="77%" height="35px;">
								<html:select property="subAccountId" onchange="getSubAcctBal()">
									<html:options collection="subAccounts" property="id"
										labelProperty="accountName" />
								</html:select>
							</td>
						</tr>
						<tr>
							<td width="23%" align="right" height="35px;">
								子账户余额：
							</td>
							<td width="77%" height="35px;">
								<span id="subaccountBal"></span>
							</td>
						</tr>
						<tr>
							<td width="23%" align="right" height="35px;">
								<span class="orang12b">*</span>直付金额：
							</td>
							<td width="77%" height="35px;">
								<html:text property="amount" alt="直付金额" size="50"
									styleClass="inputStyle" onblur="amountBlur(this);"
									onkeyup="kd();" onchange="kd();" />
								<span class="fontgraydrop14">元</span> &nbsp;&nbsp;
								<img src="<%=path%>/images/money.gif" width="17" height="17"
									border="0" style="cursor: hand" title="请使用计算器，计算直付金额"
									onclick="amountSelect();" />
								<input type="hidden" name="hideTransAmt" value="">
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								直付金额大写：
							</td>
							<td height="35px;">
								<input name="upperAmount" type="text" class="inputStyleNoborder"
									size="50" />
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								手续费收取方法：
							</td>
							<td class="fontgraydrop14" height="35px;">
								<bean:write name="feeRatioMode" />
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								<span class="orang12b">*</span>收款方银行：
							</td>
							<td class="fontgraydrop14" height="35px;">
								<html:select property="creditBankId" alt="收款方银行">
									<option value="" selected>
										----请选择收款方银行----
									</option>
									<html:options collection="creditBankList" property="id"
										labelProperty="bankName" />
								</html:select>
								&nbsp;&nbsp;
								<img src="<%=path%>/images/icon_email.gif" width="13"
									height="10" border="0" style="cursor: hand"
									title="请点击此按钮，选择收款对象" onclick="bankAccountSelect();" />
								<input type="hidden" name="peerAccountId" value="0" />
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								<span class="orang12b">*</span>收款方银行账号：
							</td>
							<td class="fontgraydrop14" height="35px;">
								<html:text property="creditAccountNo" alt="收款方银行账号"
									maxlength="32" size="50" styleClass="inputStyle"
									onblur="killSpace(this)" />
								<span class="font_gray">(存折帐号的'*'和企业帐户的'-'在此均无需输入)</span>
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								<span class="orang12b">*</span>开户行省份：
							</td>
							<td class="fontgraydrop14" height="35px;">
								<html:select property="creditProvinceId" onchange="update()"
									alt="开户行省份">
									<option value="" selected>
										----请选择收款方开户行省份----
									</option>
									<html:options collection="provinceList" property="cityId"
										labelProperty="cityName" />
								</html:select>
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								<span class="orang12b">*</span>开户行城市：
							</td>
							<td class="fontgraydrop14" height="35px;">
								<select name="creditCityId" alt="开户行城市">
									<option value="" selected>
										----请选择收款方开户行城市----
									</option>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								<span class="orang12b">*</span>开户行名称：
							</td>
							<td>
								<html:text property="creditBankName" alt="开户行名称" maxlength="20"
									size="50" styleClass="inputStyle" onblur="killSpace(this)" />
							</td>

						</tr>
						<tr>
							<td>

							</td>
							<td class="fontgraydrop14" height="35px;">

								<table width="100%" border="0" align="center" cellpadding="7"
									cellspacing="1" bgcolor="#f9e277" style="margin: 10px 0;">
									<tr>
										<td bgcolor="#fffdf5">
											<table width="100%" border="0" cellpadding="3"
												cellspacing="0">
												<tr>
													<td width="3%" height="25" valign="top"
														style="border-bottom: 1px solid #ccc;"></td>
													<td width="97%" align="left" class="red12b"
														style="border-bottom: 1px solid #ccc;">
														特别提醒
													</td>
												</tr>
												<tr>
													<td height="25" valign="top">
														&nbsp;
													</td>
													<td align="left" class="text9green">

														1）请务必正确填写收款方开户行名称！如果您不填写或者填写不正确，将会导致支付账户内的资金无法正常汇入收款方银行账户内！
													</td>
												</tr>
												<tr>
													<td height="35" valign="top">
														&nbsp;
													</td>
													<td align="left" class="text9green">

														2）此处无需重复填写银行名称与省市，只需填写具体名称如：海淀支行海体分理处。

													</td>
												</tr>
												<tr>
													<td height="35" valign="top">
														&nbsp;
													</td>
													<td align="left" class="text9green">

														3）如果您无法确定收款方开户行名称，可致电相关银行客服，报出收款方银行账号，即可获得开户行信息。

													</td>
												</tr>
												<logic:equal name="corpAccount" value="true">
													<tr>
														<td height="25" valign="top">
															&nbsp;
														</td>
														<td align="left" class="font_gray">
															警告：禁止企业用户向个人银行账户直接付款，由此带来的一切法律责任由付款企业直接负责。
														</td>
													</tr>
												</logic:equal>
											</table>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								<span class="orang12b">*</span>收款方姓名：
							</td>
							<td class="fontgraydrop14" height="35px;">
								<html:text property="creditName" alt="收款方姓名" maxlength="64"
									size="50" styleClass="inputStyle" onblur="killSpace(this)" />
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								收款方Email：
							</td>
							<td class="fontgraydrop14">
								<html:text property="creditEmail" title="收款方Email"
									maxlength="255" size="50" styleClass="inputStyle" />
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								收款方手机：
							</td>
							<td class="fontgraydrop14">
								<html:text property="creditMobile" title="收款方手机" maxlength="20"
									size="50" styleClass="inputStyle" />
							</td>
						</tr>
						<tr>
							<td align="right">
								收款方电话：
							</td>
							<td class="fontgraydrop14">
								<html:text property="creditFixedTel" title="收款方电话"
									maxlength="20" size="50" styleClass="inputStyle" />
							</td>
						</tr>
						<tr>
							<td align="right">
								<span class="orang12b">*</span> 资金用途：
							</td>
							<td>
								<html:text property="purpose" alt="资金用途" maxlength="85"
									size="50" styleClass="inputStyle" onblur="killSpace(this)" />
								<span class="font_gray">(最长85个字符) </span>
							</td>
						</tr>
						<tr>
							<td align="right" height="35px;">
								备注：
							</td>
							<td>
								<html:textarea property="remark" rows="5" cols="35" />
								<span class="font_gray">(最长85个字符) </span>
							</td>
						</tr>
						<!-- 错误信息提示 -->
						<logic:present name="org.apache.struts.action.ERROR">
							<tr>
								<td colspan="2" height="25" align="center">
									&nbsp;
									<font color="#FF0000"><html:errors /> </font>
								</td>
							</tr>
						</logic:present>
						<tr>
							<td height="55" align="right">
								&nbsp;
							</td>
							<td>
								<input name="next" type="button" class="button_style"
									onclick="submitProcess();" value="下一步" />
							</td>
						</tr>
					</table>
					<table width="100%" border="0" align="center" cellpadding="7"
						cellspacing="1" bgcolor="#f9e277" style="margin: 10px 0;">
						<tr>
							<td bgcolor="#fffdf5">
								<table width="100%" border="0" cellpadding="3" cellspacing="0">
									<tr>
										<td width="3%" height="25" valign="top"
											style="border-bottom: 1px solid #ccc;"></td>
										<td width="97%" align="left" class="red12b"
											style="border-bottom: 1px solid #ccc;">
											特别提醒
										</td>
									</tr>
									<tr>
										<td valign="top">
											&nbsp;
										</td>
										<td align="left" class="text9green">
											此功能不同于担保交易，付款后您的钱将直接进入对方账户，请确认对方身份，谨慎使用！
										</td>
									</tr>
									<tr>
										<td valign="top">
											&nbsp;
										</td>
										<td align="left" class="text9green">
											我们推荐您与亲朋好友间使用该功能，不推荐您与陌生卖家之间使用。
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</html:form>
			</div>
		</div>
	</div>
</div>
<div style="clear: both;"></div>
<script type="text/javascript" src="<%=path%>/js/layer.js"></script>
<script language="JavaScript" type="text/JavaScript">
function setCreditCityId(v) {
	if (v!=null && v!='')
		document.DrawToOtherForm.creditCityId.value = v;
}
function closeLayer(returnValue, type){
	hideLayer();
	if(type=="email"){
		document.DrawToOtherForm.peerAccountId.value=returnValue[0];
		document.DrawToOtherForm.creditBankId.value=returnValue[1];
		document.DrawToOtherForm.creditAccountNo.value=returnValue[2];
		
		document.DrawToOtherForm.creditProvinceId.value=returnValue[3];
		update();
		window.setTimeout("setCreditCityId("+returnValue[4]+")", 500);
		document.DrawToOtherForm.creditBankName.value=returnValue[5];
		document.DrawToOtherForm.creditName.value=returnValue[6];
		document.DrawToOtherForm.creditEmail.value=returnValue[7];
		document.DrawToOtherForm.creditMobile.value=returnValue[8];
		document.DrawToOtherForm.creditFixedTel.value=returnValue[9];
	}else if(type=="amount"){
		document.DrawToOtherForm.amount.value=returnValue;
		document.DrawToOtherForm.amount.focus();
		kd();
	}
}

function amountSelect(){
 	agiledata.getUserInternal(amountPopup);
}
function amountPopup(data) {
  	if(data) {
	 	openLayer("<%=path%>/page/common/simpleCalculator.jsp",400,200,false);
	} else {
		location.href="<%=path%>/page/util/session_invalid.jsp";
	}      
}

//显示预先设置的金额的大写
kd();

//显示预先设置的开户行城市
if ('<bean:write name="DrawToOtherForm" property="creditCityId"/>'!='') {
	update();
	window.setTimeout('setCreditCityId(<bean:write name="DrawToOtherForm" property="creditCityId"/>)', 500);
}
getSubAcctBal();
</script>
